<%@page import="org.lzy.pt.PluginManager"%>
<%@page import="org.lzy.pt.bean.Plugin"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@page import="org.jivesoftware.util.ParamUtils,
	java.net.URLEncoder" errorPage="error.jsp" %>
<%@page import="org.jivesoftware.util.StringUtils" %>

<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>

<%  // Get parameters
    boolean save = ParamUtils.getBooleanParameter(request,"save");
    boolean success = ParamUtils.getBooleanParameter(request,"success");
    String T_Name = ParamUtils.getParameter(request,"T_Name");
    String T_Ver = ParamUtils.getParameter(request,"T_Ver");
    String T_Path = ParamUtils.getParameter(request,"T_Path");
    String T_Data = ParamUtils.getParameter(request,"T_Data");
    Map<String, String> errors = new HashMap<String, String>();

    // Handle a cancel
    if (request.getParameter("cancel") != null) {
     	response.sendRedirect("plugin-properties.jsp?T_Name="+T_Name+"&T_Ver="+T_Ver);
        return;
    }

    Plugin plugin = PluginManager.getInstance().getPlugin(T_Name, Integer.parseInt(T_Ver));

    // Handle a save
    if (save) {

        if (errors.size() == 0) {

        	plugin.setT_Data(T_Data);
        	plugin.setT_Path(T_Path);
        	
        	PluginManager.getInstance().updatePlugin(plugin);
            
            response.sendRedirect("plugin-properties.jsp?editsuccess=true&T_Name="+T_Name+"&T_Ver="+T_Ver);
            return;
        }
    }
%>

<html>
    <head>
        <title><fmt:message key="plugin.edit.form.title"/></title>
        <meta name="subPageID" content="plugin-properties"/>
        <meta name="extraParams" content="<%= "T_Name="+T_Name+"&T_Ver="+T_Ver %>"/>
    </head>
    <body>
<%  if (!errors.isEmpty()) { %>

    <div class="jive-error">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr>
            <td class="jive-icon"><img src="images/error-16x16.gif" width="16" height="16" border="0" alt=""/></td>
            <td class="jive-icon-label">
            <% if (errors.get("name") != null) { %>
                <fmt:message key="plugin.create.invalid_name" />
            <% } else if (errors.get("email") != null) { %>
                <fmt:message key="plugin.create.invalid_email" />
            <% } %>
            </td>
        </tr>
    </tbody>
    </table>
    </div>
    <br>

<%  } else if (success) { %>

    <div class="jive-success">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr><td class="jive-icon"><img src="images/success-16x16.gif" width="16" height="16" border="0" alt=""></td>
        <td class="jive-icon-label">
        <fmt:message key="plugin.edit.form.update" />
        </td></tr>
    </tbody>
    </table>
    </div><br>

<%  } %>

<p>
<fmt:message key="plugin.edit.form.info" />
</p>

<form action="plugin-edit-form.jsp">

<input type="hidden" name="save" value="true">

<fieldset>
    <legend><fmt:message key="plugin.edit.form.property" /></legend>
    <div>
    <table cellpadding="3" cellspacing="0" border="0" width="100%">
    <tbody>
        <tr>
            <td class="c1">
                <fmt:message key="plugin.T_Name" />:
            </td>
            <td>
            	<input type="hidden" name="T_Name" value="<%= plugin.getT_Name() %>" >
            	<input type="text" size="30" maxlength="150" name="T_CnName" value="<%= plugin.getT_CnName() %>" readonly="readonly">
            </td>
        </tr>
        <tr>
            <td class="c1">
                <fmt:message key="plugin.T_Ver" />: 
            </td>
            <td>
                <input type="text" size="30" maxlength="150" name="T_Ver" value="<%= plugin.getT_Ver() %>" readonly="readonly">
            </td>
        </tr>
        <tr>
            <td class="c1">
                <fmt:message key="plugin.T_Path" />: 
            </td>
            <td>
                <input type="text" size="30" maxlength="150" name="T_Path"
                 value="<%= ((plugin.getT_Path()!=null) ? plugin.getT_Path() : "") %>"/>
            </td>
        </tr>
<!--         <tr> -->
<!--             <td class="c1"> -->
<%--                 <fmt:message key="plugin.T_Data" />:  --%>
<!--             </td> -->
<!--             <td> -->
<!--                  <input type="text" size="30" maxlength="150" name="T_Data" -->
<%--                  value="<%= ((plugin.getT_Data()!=null) ? plugin.getT_Data() : "") %>"> --%>
<!--             </td> -->
<!--         </tr> -->
<!--         <tr> -->
<!--         	<td colspan="2"> -->
<!--         		<pre> -->
<%--         			<%=plugin.getT_Data() %> --%>
<!--         		</pre> -->
<!--         	</td> -->
<!--         </tr> -->
    </tbody>
    </table>
    </div>

</fieldset>

<br><br>

<input type="submit" value="<fmt:message key="global.save_properties" />">
<input type="submit" name="cancel" value="<fmt:message key="global.cancel" />">

</form>

<br/>

<span class="jive-description">
* <fmt:message key="plugin.create.requied" />
</span>

    </body>
</html>